using System.Drawing;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace _3Dto2D.Configuration;

public class RenderSettings
{
    public int OutputWidth { get; set; } = 250;
    public int OutputHeight { get; set; } = 250;

    [JsonConverter(typeof(ColorJsonConverter))]
    public Color BackgroundColor { get; set; } = Color.Black;

    public bool EnableAntiAliasing { get; set; } = true;
    public float RenderScale { get; set; } = 1.0f;
    public int CharacterGlobalOffsetX { get; set; } = 100;
    public int CharacterGlobalOffsetY { get; set; } = 150;

    // Export settings
    public string DefaultMeshPath { get; set; } = @".\Mesh";
    public string DefaultDataPath { get; set; } = @".\Data";
    public string DefaultOutputPath { get; set; } = @".\CompletedLibs";

    // Performance settings
    public int MaxConcurrentRenders { get; set; } = Environment.ProcessorCount;
    public bool UseGpuAcceleration { get; set; } = true;
    public int TexturePoolSize { get; set; } = 100;
}

public class ColorJsonConverter : JsonConverter<Color>
{
    public override Color Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
    {
        var colorString = reader.GetString();
        return ColorTranslator.FromHtml(colorString ?? "#000000");
    }

    public override void Write(Utf8JsonWriter writer, Color value, JsonSerializerOptions options)
    {
        writer.WriteStringValue(ColorTranslator.ToHtml(value));
    }
}
